import Vue from 'vue';
Vue.filter('fixedPrice', function(value, fixedNum) {
  if (fixedNum === void 0) {
    fixedNum = 2;
  }
  return '￥' + (parseFloat(value) / 100).toFixed(fixedNum);
});
Vue.filter('filterPrice', function(value, fixedNum) {
  if (fixedNum === void 0) {
    fixedNum = 2;
  }
  return (parseFloat(value) / 100).toFixed(fixedNum);
});
/**
 * 返回年月日
 * @export
 * @param {Date} date
 * @param {string} [splitor='-']
 * @returns
 */
Vue.filter('getDate', function(date, splitor = '-') {
  const year = date.getFullYear();
  const month = date.getMonth() + 1;
  const day = date.getDate();
  return `${year}${splitor}${addZeroPrefix(month)}${splitor}${addZeroPrefix(day)}`;
});
/**
 * 返回时分秒/时分
 * @export
 * @param {*} date
 * @param {boolean} [withSecond=false]
 * @returns
 */
Vue.filter('getTime', function(date, withSecond = false) {
  const hour = date.getHours();
  const minute = date.getMinutes();
  const second = date.getSeconds();
  return withSecond ? `${addZeroPrefix(hour)}:${addZeroPrefix(minute)}:${addZeroPrefix(second)}` : `${hour}:${addZeroPrefix(minute)}`;
});
// 个位数，加0前缀
function addZeroPrefix(number) {
  return number < 10 ? `0${number}` : number;
}
Vue.filter('addZeroPrefix', addZeroPrefix);
Vue.filter('phoneChange', function(phoneNum) {
  if (phoneNum) {
    const numStr = '' + phoneNum;
    return numStr.substr(0, 3) + '****' + numStr.substr(7);
  } else {
    return phoneNum;
  }
});
